package gps.monitor.jt809server.protocol.codec;

import gps.monitor.jt809server.protocol.Jt809ParseException;
import gps.monitor.jt809server.protocol.model.Jt809Message1202;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;

/**
 * @author cyq
 * @date 2021/11/7
 * @desc talk is cheep,show me the code
 */
public class Jt809SubHandler1202 implements Jt809UpExgMsgHandler<Jt809Message1202> {

    @Override
    public Jt809Message1202 readBody(ByteBuf byteBuf) throws Jt809ParseException {
        Jt809Message1202 message1202 = new Jt809Message1202();
        readUpExgMsgHeader(message1202, byteBuf);

        message1202.setEncrypy(byteBuf.readByte());
        int day = byteBuf.readByte();
        int month = byteBuf.readByte();
        int year = Integer.valueOf(ByteBufUtil.hexDump(byteBuf.readBytes(2)), 16);
        int hour = byteBuf.readByte();
        int minute = byteBuf.readByte();
        int second = byteBuf.readByte();
        message1202.setDateTime(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
        message1202.setLon(Integer.valueOf(ByteBufUtil.hexDump(byteBuf.readBytes(4)), 16));
        message1202.setLat(Integer.valueOf(ByteBufUtil.hexDump(byteBuf.readBytes(4)), 16));
        //...
        return message1202;
    }
}
